﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Barbar.UrlGuard.Controls {
  public class ChainContextMenu : ContextMenu, ILocalizable {
    private MenuItem m_AddChain;
    private MenuItem m_EditChain;
    private MenuItem m_AddUrl;
    private MenuItem m_RemoveChain;

    public event EventHandler<ChainContextMenuEventArgs> Command;

    public ChainContextMenu() {
      m_AddChain = new MenuItem("Add new chain", OnMenuClick);
      m_AddChain.Tag = ChainContextMenuCommand.AddChain;

      m_EditChain = new MenuItem("Edit chain", OnMenuClick);
      m_EditChain.Tag = ChainContextMenuCommand.EditChain;

      m_AddUrl = new MenuItem("Add new url", OnMenuClick);
      m_AddUrl.Tag = ChainContextMenuCommand.AddUrl;

      m_RemoveChain = new MenuItem("Remove this chain", OnMenuClick);
      m_RemoveChain.Tag = ChainContextMenuCommand.RemoveChain;

      MenuItems.AddRange(new MenuItem[] { m_AddChain, m_EditChain, m_AddUrl, m_RemoveChain });
    }

    private void OnMenuClick(object sender, EventArgs e) {
      if (Command != null) {
        MenuItem menuItem = (MenuItem)sender;
        ChainContextMenuCommand command = (ChainContextMenuCommand)menuItem.Tag;
        Command(this, new ChainContextMenuEventArgs(command));
      }
    }

    #region ILocalizable Members

    public void Localize(ILocalizator localizator) {
      if (localizator == null)
        throw new ArgumentNullException("localizator");

      m_AddChain.Text = localizator.Translate("TreeCommand_AddChain");
      m_EditChain.Text = localizator.Translate("TreeCommand_EditChain");
      m_AddUrl.Text = localizator.Translate("TreeCommand_AddUrl");
      m_RemoveChain.Text = localizator.Translate("TreeCommand_RemoveChain");
    }

    #endregion
  }
}
